package com.jorado.etl.util;

import io.lettuce.core.RedisClient;
import io.lettuce.core.api.StatefulRedisConnection;
import io.lettuce.core.api.sync.RedisStringCommands;

public class RedisUtils {

    private RedisClient client;
    private StatefulRedisConnection<String, String> connection;
    private RedisStringCommands sync;

    public RedisUtils(String host) {
        this.client = RedisClient.create("redis://" + host);
        this.connect();
    }

    public void connect() {
        connection = client.connect();
        sync = connection.sync();
    }

    public String syncGet(String key) {

        Object o = sync.get(key);
        return o == null ? "" : o.toString();
    }

    public void syncSet(String key, String value) {

        sync.set(key, value);
    }
}
